package 力扣_树算法.路径;

/**
 * @author zx
 * @create 2022-09-12 22:03
 */
public class 求根节点到叶节点数字之和_129 {
    int res = 0;
    public int sumNumbers(TreeNode root) {
        helper(root,0);
        return res;
    }
    private void helper(TreeNode root, int path){
        if(root == null){
            return;
        }
        path = path * 10 + root.val;
        if(root.left == null && root.right == null){
            res += path;
        }
        helper(root.left,path);
        helper(root.right,path);
    }
}
